package com.wen.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author Devin QQ:1441289544
 * @description 获取Spring工厂工具类
 * @create 2022-02-28 14:10
 */
@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    //保留下来这个工厂
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextUtils.applicationContext = applicationContext;
    }

    /**
     * 获取Spring工厂中的bean
     * @param beanName
     * @return
     */
    public static Object getBean(String beanName){
        return applicationContext.getBean(beanName);
    }
}
